﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void BtnCz_Click(object sender, EventArgs e)
    {
        this.TxtID.Text = null;
        this.TxtName.Text = null;
        this.TxtPhone.Text = null;
        this.TxtPwd1.Text = null;
        this.TxtPwd2.Text = null;
        this.TxtSex.Text = null;
        this.TxtSite.Text = null;
        TxtAge.Text = null;
    }

    protected void LinkDl_Click(object sender, EventArgs e)
    {
        Response.Redirect("Logon.aspx");
    }

    protected void BtnZc_Click(object sender, EventArgs e)
    {
        string sql = string.Format("select count(*) from Patient where IDCard='{0}'", this.TxtID.Text);
        int n = Convert.ToInt32(DBHelper.GetScalar(sql));
        if (n == 0)
        {
            if (this.TxtPwd1.Text == this.TxtPwd2.Text)
            {
                string updatesql = string.Format("insert Patient(Name,PassWord,IDCard,Phone,Age,Sex,Address) values('{0}','{1}','{2}','{3}',{4},'{5}','{6}')", this.TxtName.Text, this.TxtPwd1.Text, this.TxtID.Text, this.TxtPhone.Text,TxtAge.Text, this.TxtSex.Text, this.TxtSite.Text);
                DBHelper.GetNonQuery(updatesql);
                Response.Write("<script>alert('注册成功！')</script>");
                this.TxtID.Text = null;
                this.TxtName.Text = null;
                this.TxtPhone.Text = null;
                this.TxtSex.Text = null;
                this.TxtSite.Text = null;
                TxtAge.Text = null;
            }
            else
            {
                Response.Write("<script>alert('密码不一致,请重新输入！')</script>");
                this.TxtPwd1.Text = "";
                this.TxtPwd2.Text = "";
            }

        }
        else
        {
            Response.Write("<script>alert('用户已存在。')</script>");
            this.TxtID.Text = null;
            this.TxtName.Text = null;
            this.TxtPhone.Text = null;
            this.TxtSex.Text = null;
            this.TxtSite.Text = null;
            TxtAge.Text = null;
        }
    }
}